<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>千千万能工具箱fc模拟器</title>
		<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3419308738737930"
		     crossorigin="anonymous"></script>
	</head>
	<script src="https://www.lqcpws.cn/questionnaire/vue2.6.11/vue.js"></script>
	<script src="https://www.lqcpws.cn/questionnaire/element2.4.7/index.js"></script>
	<script src="https://www.lqcpws.cn/questionnaire/js/jquery.min.js"></script>
	<link href="https://www.lqcpws.cn/questionnaire/element2.4.7/index.css" rel="stylesheet" />
	<script src="https://www.lqcpws.cn/nes/js/localforage.min.js"></script>
	<script src="https://www.lqcpws.cn/nes/js/jsnes.min.js"></script>
	<script src="https://www.lqcpws.cn/nes/js/lz-string.min.js"></script>
	<script src="js/run.js"></script>
    <script src="js/gamecontroller.js"></script>


	<body>
		<div id="app">
			
			<div v-loading="loading">

<div class="gamePadDesc">
	<h3>手柄描述</h3>
	<p>连接需要按一下操作键才能激活手柄</p>
	<p>只支持单手柄</p>
	<p>支持自动扫描手柄状态</p>
	<p>支持右侧基本按键，摇杆暂不支持</p>
	<h3>手柄状态</h3>
	<p><el-tag type="success" v-if="isConnectGamePad">手柄已连接</el-tag></p>
	<p><el-tag type="danger" v-if="!isConnectGamePad">手柄已断开</el-tag></p>
</div>



				<div class="codeDesc">
<el-button  type="warning" style="text-align: center;" @click="fullscreen()">全屏模式</el-button>
					<el-button type="primary" style="text-align: center;" @click="save()">保存游戏进度</el-button>
				
					<h3 style="text-align: center;">键位图</h3>
					<img src="https://www.lqcpws.cn/nes/imgs/169093984799775.png" width="300">
				</div>

				<div style="text-align: center;"><img src="https://www.lqcpws.cn/nes/imgs/169093772570090.png"
						width="400" /> </div>
				<h3 style="text-align: center;">{{gameInfo.name}}</h3>

				<div style=" width: 75%;">

					<canvas id="nes-canvas" width="500" height="240" style="width: 100%;margin-left: 40%;" />
				</div>

			</div>

		</div>
	</body>

	<style>
		body {
			overflow-x: hidden;
		}

		.codeDesc {
			position: fixed;

			left: 75%;

			top: 10%;
		}
		
		.gamePadDesc {
			position: fixed;
		
			left: 10%;
		
			top: 10%;
		}
	</style>


	<script>
		
		 let baseUrl = "http://192.168.1.121:8848"



		var app = new Vue({
			el: '#app',
			data: {
				id: undefined,
				loading: false,
				token: undefined,

				gameInfo: {},
				updateSupport:true,
				isSupportGamePad:false,
				isConnectGamePad:false,
				gamepad:{},
				gamePadRunTime:undefined,
				
			},
			mounted() {
				
				
				// console.log(window.location.search)
				this.$message.success('已使用jsnes引擎加载游戏');
				if (window.location.search.trim() == "") {
					this.loading = true
					this.$message.error('缺少核心数据');
					return
				}
				let str = window.location.search.substring(1, window.location.search.length)
				let arr = str.split("&");
			
				this.id = arr[0].split("=")[1]
			if(arr.length>1){
					this.token = arr[1].split("=")[1]
			}

				if (this.id == undefined ) {
					this.loading = true
					this.$message.error('缺少核心数据');
					return
				}
				if (this.id.trim() == "" ) {
					this.loading = true
					this.$message.error('缺少核心数据');
					return
				}

               

 
				this.getGameInfo()
               this.requestCount()

				this.submitForm()
				
				this.listenButtons();
				
					    
					

			},
			methods: {

			
				listenButtons(){
					let _this=this
		gameControl.on('disconnect', function(gp) {
								  if(lineAKey!=undefined){
								  clearInterval(lineAKey)
								  }
								  if(lineBKey!=undefined){
								  clearInterval(lineBKey)
								  }
								 _this.isConnectGamePad=false
								  })
		      gameControl.on('connect', function(gp) {
				 _this.isConnectGamePad=true
				  // console.log(gp)
				       //开始
		        gp.on('start', function() {
					// console.log('start on')
		       
		        })
		          .before('start', function() {
					   simulateKeyPress(71)
					  	// console.log('start pressed')
		    
		          })
		          .after('start', function() {
					   simulateKeyRelease(71)
					  	// console.log('start released')
		       
		          });
				  //选择
		        gp.on('select', function() {
					// console.log('select on')
		          
		        })
		          .before('select', function() {
					  simulateKeyPress(70)
		           // console.log('select pressed')
		          })
		          .after('select', function() {
					  simulateKeyRelease(70)
					  // console.log('select released')
		   
		          });
		    
		
		gp.on('button12', function() {
						// console.log('up on')
		    
		  })
		    .before('button12', function() {
				simulateKeyPress(87)
		     // console.log('up pressed')
		    })
		    .after('button12', function() {
				simulateKeyRelease(87)
						  // console.log('up released')
			   
		    });
		
			
			gp.on('button13', function() {
							// console.log('down on')
			    
			  })
			    .before('button13', function() {
					simulateKeyPress(83)
			     // console.log('down pressed')
			    })
			    .after('button13', function() {
					simulateKeyRelease(83)
							  // console.log('down released')
				   
			    });
			
				
				
				
				gp.on('button14', function() {
								// console.log('left on')
				    
				  })
				    .before('button14', function() {
						simulateKeyPress(65)
				     // console.log('left pressed')
				    })
				    .after('button14', function() {
						simulateKeyRelease(65)
								  // console.log('left released')
					   
				    });
				
					
					gp.on('button15', function() {
									// console.log('right on')
					    
					  })
					    .before('button15', function() {
							simulateKeyPress(68)
					     // console.log('right pressed')
					    })
					    .after('button15', function() {
							simulateKeyRelease(68)
									  // console.log('right released')
						   
					    });
						
						
						
						
						gp.on('button0', function() {
										// console.log('A on')
						    
						  })
						    .before('button0', function() {
						     // console.log('A pressed')
							 simulateKeyPress(75)
						    })
						    .after('button0', function() {
								simulateKeyRelease(75)
										  // console.log('A released')
							   
						    });
						
						
						
						gp.on('button1', function() {
										// console.log('lineA on')
						    
						  })
						    .before('button1', function() {
								 simulateKeyPress(73)
						     // console.log('lineA pressed')
						    })
						    .after('button1', function() {
								 simulateKeyRelease(73)
										  // console.log('lineA released')
							   
						    });
							
							gp.on('button2', function() {
											// console.log('B on')
							    
							  })
							    .before('button2', function() {
									simulateKeyPress(74)
							     // console.log('B pressed')
							    })
							    .after('button2', function() {
									simulateKeyRelease(74)
											  // console.log('B released')
								   
							    });
								
								
								gp.on('button3', function() {
												// console.log('lineB on')
								    
								  })
								    .before('button3', function() {
										simulateKeyPress(85)
								     // console.log('lineB pressed')
								    })
								    .after('button3', function() {
										simulateKeyRelease(85)
												  // console.log('lineB released')
									   
								    });
						
						
						
						
						
						
				
						
					});
				

				},
				fullscreen(){
					const element = document.documentElement;
					if (element.requestFullscreen) {
					  element.requestFullscreen();
					}
				},
				submitForm() {
					// let ys=	LZString.compressToBase64(JSON.stringify(nes.toJSON()))
					// 	console.log(JSON.parse(LZString.decompressFromBase64(ys)))
					let _this = this
					$.ajax({
						type: 'post',
			
						url: baseUrl + "/pc/nesGame/updatePlayCount",
						data: {
							id: _this.id
						},
						success: function(res) {


						}


					})

				},
				requestCount() {
					// let ys=	LZString.compressToBase64(JSON.stringify(nes.toJSON()))
					// 	console.log(JSON.parse(LZString.decompressFromBase64(ys)))
					let _this = this
					$.ajax({
						type: 'get',
						url: baseUrl + "/pc/requestCountByDay",
						success: function(res) {
				
				
						}
				
				
					})
				
				},
				getGameInfo() {
					let _this = this
					this.loading = true
					$.ajax({
						type: 'get',
						url: baseUrl + "/pc/nesGame/getNesGame",
					
						data: {
							id: _this.id
						},
						success: function(res) {

							if (res.code == 401 || res.data == undefined || res.code == 500) {
								_this.$message.error('缺少核心数据');
							} else {
								_this.loading = false
								_this.gameInfo = res.data

								nes_load_url("nes-canvas", _this.gameInfo.nesUrl)


							}
						}


					})

				},
				save() {
               
					localStorage.removeItem(this.gameInfo.nesUrl)
					saveData(this.gameInfo.nesUrl)
			
					
					
					
					
					
					
					
					

				},
				
					
					
					
					
				

			}


		})





	
	</script>



</html>
